import { getSystemConfig } from "@/common/apis/common.js";

const state = {
  logoText: "",
  isLaunch: "0",
  satisfyPrice: 0,
};

const getters = {
  logoText: (state) => state.logoText,
  isLaunch: (state) => state.isLaunch,
  satisfyPrice: (state) => state.satisfyPrice,
};

const mutations = {
  SET_LOGO_TEXT(state, text) {
    state.logoText = text;
  },
  SET_IS_LAUNCH(state, text) {
    state.isLaunch = text;
  },
  SET_SATISFY_PRICE(state, text) {
    state.satisfyPrice = text;
  },
};

const actions = {
  async fetchLogoText({ commit }) {
    const response = await getSystemConfig({ key: "logo_text" });
    if (response) {
      commit("SET_LOGO_TEXT", response.data.value);
    }
  },
  async fetchIsLaunch({ commit }) {
    const response = await getSystemConfig({ key: "is_launch" });
    if (response) {
      commit("SET_IS_LAUNCH", response.data.value);
    }
  },
  async fetchSatisfyPrice({ commit }) {
    const response = await getSystemConfig({ key: "satisfy_price" });
    if (response) {
      commit("SET_SATISFY_PRICE", response.data.value);
    }
  },
};

export default {
  state,
  getters,
  mutations,
  actions,
};
